/*
 Navicat Premium Data Transfer

 Source Server         : 虚拟机oracle
 Source Server Type    : Oracle
 Source Server Version : 110200
 Source Host           : 192.168.199.183:1521
 Source Schema         : SYSTEM

 Target Server Type    : Oracle
 Target Server Version : 110200
 File Encoding         : 65001

 Date: 04/12/2021 15:21:20
*/


-- ----------------------------
-- Table structure for T_BORROW
-- ----------------------------
DROP TABLE CT.T_BORROW;
CREATE TABLE CT.T_BORROW (
  "BORROWID" NUMBER NOT NULL,
  "USERID" NUMBER NOT NULL,
  "BOOKID" NUMBER NOT NULL,
  "BORROWTIME" DATE NOT NULL,
  "RETURNTIME" DATE
);

-- ----------------------------
-- Records of T_BORROW
-- ----------------------------
INSERT INTO CT.T_BORROW VALUES ('26', '11', '2', TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO CT.T_BORROW VALUES ('27', '11', '1', TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO CT.T_BORROW VALUES ('28', '11', '4', TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO CT.T_BORROW VALUES ('30', '14', '2', TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-11-19 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO CT.T_BORROW VALUES ('32', '14', '4', TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-11-18 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO CT.T_BORROW VALUES ('38', '14', '1', TO_DATE('2021-11-19 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-11-19 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO CT.T_BORROW VALUES ('39', '14', '1', TO_DATE('2021-11-19 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-11-19 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO CT.T_BORROW VALUES ('40', '14', '1', TO_DATE('2021-11-19 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-11-19 00:00:00', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO CT.T_BORROW VALUES ('101', '14', '2', TO_DATE('2021-12-04 15:00:00', 'SYYYY-MM-DD HH24:MI:SS'), TO_DATE('2021-12-04 15:00:06', 'SYYYY-MM-DD HH24:MI:SS'));

-- ----------------------------
-- Primary Key structure for table T_BORROW
-- ----------------------------
ALTER TABLE CT.T_BORROW ADD CONSTRAINT "SYS_C0011127" PRIMARY KEY ("BORROWID");

-- ----------------------------
-- Checks structure for table T_BORROW
-- ----------------------------
ALTER TABLE CT.T_BORROW ADD CONSTRAINT "SYS_C0011122" CHECK ("BORROWID" IS NOT NULL) NOT DEFERRABLE INITIALLY IMMEDIATE NORELY VALIDATE;
ALTER TABLE CT.T_BORROW ADD CONSTRAINT "SYS_C0011123" CHECK ("USERID" IS NOT NULL) NOT DEFERRABLE INITIALLY IMMEDIATE NORELY VALIDATE;
ALTER TABLE CT.T_BORROW ADD CONSTRAINT "SYS_C0011124" CHECK ("BOOKID" IS NOT NULL) NOT DEFERRABLE INITIALLY IMMEDIATE NORELY VALIDATE;
ALTER TABLE CT.T_BORROW ADD CONSTRAINT "SYS_C0011125" CHECK ("BORROWTIME" IS NOT NULL) NOT DEFERRABLE INITIALLY IMMEDIATE NORELY VALIDATE;

create sequence seq_t_borrow
    minvalue 1
    maxvalue 99999999
    start with 17
    increment by 102;

-- ----------------------------
-- Triggers structure for table T_BORROW
-- ----------------------------
CREATE TRIGGER CT.t_borrow_trig BEFORE INSERT ON CT.T_BORROW REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW
declare
begin
    select seq_t_borrow.nextval into :new.borrowid from dual;
end dept_trig;
/
